package com.book.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.book.model.entity.Banner;
import com.book.model.entity.BookCategory;
import com.book.mapper.BookCategoryMapper;
import com.book.model.vo.BookCategoryPageVO;
import com.book.service.BookCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 书本类别 服务实现类
 * </p>
 *
 * @author auto
 * @since 2025-04-02 06:38:55
 */
@Service
public class BookCategoryServiceImpl extends ServiceImpl<BookCategoryMapper, BookCategory> implements BookCategoryService {

    @Override
    public Page<BookCategory> getBookCategoryListByPage(Integer page, Integer size,String search) {
        Page<BookCategory> bannerPage = new Page<>(page, size);
        LambdaQueryWrapper<BookCategory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(BookCategory::getCreateTime);
        queryWrapper.eq(StringUtils.isNotBlank(search),BookCategory::getCategory,search);
        Page<BookCategory> resultPage = this.page(bannerPage, queryWrapper);
        return resultPage;
    }

    @Override
    public List<BookCategory> getBookCategoryList() {
        return this.list();
    }

    @Override
    public boolean addCategory(String name) {
        BookCategory bookCategory = new BookCategory();
        bookCategory.setCategory(name);
        bookCategory.setCreateTime(new Date());
        return this.save(bookCategory);
    }
}
